<?php

namespace App\Filament\User\Pages;

use Filament\Pages\Page;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use App\Models\Project;

class ComponentList extends Page
{
    protected static ?string $navigationIcon = 'heroicon-o-document-text';
    protected static string $view = 'filament.user.pages.component-list';
    protected static ?string $navigationLabel = '组件库';
    protected static ?string $title = '';
    protected static ?string $slug = 'components/{project_id?}/{save_status?}';

    public ?int $project_id = 0;
    public ?string $save_status = 'unsaved';

    public $projects;

    public $projects_count = 0;

    public function mount(?string $project_id = null, ?string $save_status = null): void
    {
        $this->project_id = $project_id;
        $this->save_status = $save_status;
        $this->projects = Project::where('user_id', auth()->id())->get();
        $this->projects_count = Project::where('user_id', auth()->id())->count();
    }

    protected function getRouteParameters(): array
    {
        return [
            'project_id' => $this->project_id,
            'save_status' => $this->save_status,
        ];
    }

    public function getView(): string
    {
        return parent::getView();
    }

    public static function getUrl(array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string
    {
        $parameters['project_id'] = $parameters['project_id'] ?? null;
        $parameters['save_status'] = $parameters['save_status'] ?? null;
        return parent::getUrl($parameters, $isAbsolute, $panel, $tenant);
    }



    public function render(): View
    {
        return parent::render();
    }
}
